import { noSystemReferences } from '@app-cad-env/product/utils';
import { PickInputRJSFFormat } from '@app-cad/common/components/command-form/constants';
import { RJSFSchema } from '@rjsf/utils';

export const schema: RJSFSchema = {
  properties: {
    select: {
      type: 'number',
      format: PickInputRJSFFormat.PickProduct,
    },
    constraints: {
      title: '配合',
      type: 'array',
      items: {
        type: 'object',
        properties: {
          id: {
            type: 'string',
            title: '约束',
          },
          title: {
            type: 'string',
            title: '名称',
          },
          used: {
            type: 'boolean',
            title: '启用',
          },
          reuse: {
            type: 'boolean',
            title: '使用现有参考',
          },
          target: {
            type: 'string',
            title: '参考对象',
            format: PickInputRJSFFormat.PickALL,
          },
          reverse: {
            type: 'boolean',
            title: '反转',
          },
        },
      },
    },
  },
};

export const extraUiSchema = {
  select: {
    'ui:placeholder': '请输入零件',
    'ui:autofocus': true,
    'ui:options': {
      pickFilter: noSystemReferences,
    },
  },
  constraints: {
    'ui:classNames': 'constraints-to-copy-with',
    'ui:options': {
      orderable: false,
      addable: false,
      removable: false,
    },
    items: {
      id: {
        'ui:widget': 'hidden',
      },
      title: {
        'ui:widget': 'hidden',
      },
      used: {
        'ui:widget': 'amcaxSwitch',
      },
      reverse: {
        'ui:widget': 'reverseIcon',
        'ui:label': false,
      },
    },
  },
};
